package com.zhangliuliu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhangliuliu.bean.GroupBean;
import com.zhangliuliu.dao.GroupDao;
import com.zhangliuliu.service.GroupService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class GroupServiceImpl extends ServiceImpl<GroupDao, GroupBean> implements GroupService {


    @Override
    public void addGroup(GroupBean groupBean) {
        // 第一错误点：自己写了sql语句 需要调用自己写的这个方法
        // 第二错误点：有点小粗心，areaBean.areaId.areaId 这里多写了一次id
        // 第三错误点：表名group和我们mysql关键字重复 其他没问题了
       this.baseMapper.addGroup(groupBean);
    }

    @Override
    public GroupBean find(int id) {
     return   this.baseMapper.find(id);
    }

    @Override
    public void updateGroup(int id, String leader, String tell) {
         GroupBean groupBean = new GroupBean();
         groupBean.setGroupId(id);
         groupBean.setLeader(leader);
         groupBean.setTell(tell);
         this.updateById(groupBean);
    }


    @Override
    public IPage<GroupBean> cutByItem(int pageNo, int pageSize, String name, Integer areaId) {
         Page<GroupBean> Page = new Page<>(pageNo, pageSize);
        QueryWrapper wrapper = new QueryWrapper();
        if (name!=null&&!name.equals("")){
            wrapper.eq("gro_name",name);
        }
        if (areaId!=null){
            wrapper.eq("fk_areaId",areaId);
        }
        IPage<GroupBean> ipage=this.page(Page,wrapper);
        return ipage;
    }
}
